<?php
/**
 * Functions to be used throughout the site
 */

/****** Global Variables ******/
$db = "group5";
$dbUsr = "group5";
$dbPass = "group5";
 
/**
 * Connects to group 5 database. Returns db connection or
 * false if connection fails
 */
function dbConn() {
	$link = mysqli_connect("127.0.0.1",$dbUsr,$dbPass,$db);
	if (mysqli_connect_errno()) {
		return false;
	} else {
		return $link;
	}
}
	
/**
 * Verifies input is not empty. Uses mysqli real escape
 * string to achieve basic security; chosen for simplicity.
 * Accepts string.
 * Returns escaped string input, or false if database
 *     connection fails or string is empty.
 */
function inputEscCheckNull($input) {
	// strlen will return 0 if $input is empty OR is NULL
	if (strlen($input) === 0) {
		return false;
	}
	$link = dbConn();
	$input = mysqli_real_escape_string($link,$input);
	mysqli_close($link);
	return $input;
}
/**
 * Checks that $input does not exceed a character length
 * of $maxlen.
 */
function inputFullCheck($input, $maxlen) {
	if (strlen($input) !== 0 &&
		strlen($input) <= $maxlen)
	{
		return true;
	} else {
		return false;
	}
}
